from pyecharts.charts import Radar
from pyecharts import options as opts

# 定义雷达图的指示器
indicators = [
    opts.RadarIndicatorItem(name="销售", max_=6500),
    opts.RadarIndicatorItem(name="管理", max_=16000),
    opts.RadarIndicatorItem(name="信息技术", max_=30000),
    opts.RadarIndicatorItem(name="客服", max_=38000),
    opts.RadarIndicatorItem(name="研发", max_=52000),
    opts.RadarIndicatorItem(name="市场", max_=25000),
]

# 定义数据
data = [
    {
        "value": [4300, 10000, 28000, 35000, 50000, 19000],
        "name": "预算分配"
    },
    {
        "value": [5000, 14000, 28000, 31000, 42000, 21000],
        "name": "实际开销"
    }
]

# 创建雷达图
radar = (
    Radar()
    .add_schema(
        schema=indicators,
        shape="circle"  # 可选：'circle' 或 'polygon'
    )
    .add(
        series_name="预算分配",
        data=[data[0]["value"]],
        areastyle_opts=opts.AreaStyleOpts(opacity=0.5)
    )
    .add(
        series_name="实际开销",
        data=[data[1]["value"]],
        areastyle_opts=opts.AreaStyleOpts(opacity=0.5)
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="雷达图示例"),
        legend_opts=opts.LegendOpts(orient="vertical", pos_top="10%", pos_left="2%")
    )
)

# 渲染图表为HTML文件
radar.render("radar_chart.html")